package ldh.im.server.handler;

import io.netty.buffer.ByteBuf;
import ldh.im.dto.DtoData;
import ldh.im.dto.Header;
import ldh.im.handle.TransferDataCoderHandler;
import ldh.im.server.dto.ServerHeader;

import java.util.List;

public class TransferDataServerCoderHandler extends TransferDataCoderHandler {

    protected Header createHeader() {
        return new ServerHeader();
    }

    protected Object handleData(ByteBuf in, Header header, int bodyTotal, List<Object> out) {
        short coder = in.readShort();
        ByteBuf byteBuf = in.readRetainedSlice(bodyTotal-2);
        out.add(new DtoData(coder, byteBuf));
        return byteBuf;
    }

//    // 客户端头部最少9字节
//    @Override
//    protected int writeHeaders(ByteBuf byteBuf, Header header) {
//        byteBuf.writeByte(header.getVersion());
//        byteBuf.writeShort(header.getCoder());
//
//        int length = writeHeaderProperties(byteBuf, header.getProperties()) + 7;
//        return length;
//    }
}
